﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Linq;
using System.Data.Linq;
using System.Collections.Generic;
namespace Exact_Extension
{
    public partial class ProformaInvRpt : DevExpress.XtraReports.UI.XtraReport
    {

        List<ISHCMC_ListInvoiceDetail> ListInvoiceDetail;
        string title ="";
        ISHCMC_StudentPayment itemStudentPayment;
        ISHCMC_V_StudentListWithDebtor itemStudent;
        public ProformaInvRpt()
        {
            InitializeComponent();
           
        }
        public void SetListInvoiceDetail(List<ISHCMC_ListInvoiceDetail> _ListInvoiceDetail,ISHCMC_StudentPayment _itemStudentPayment,ISHCMC_V_StudentListWithDebtor _itemStudent)
        {
            ListInvoiceDetail = _ListInvoiceDetail;
            itemStudentPayment = _itemStudentPayment;
            itemStudent = _itemStudent;
                
        }
        public void SetTitle(string _title)
        {
            title = _title;
        }
        public void SetAttention(string attention)
        {
            this.lbAttention.Text = attention;
        }
        private void ProformaInv_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            double OtherFee = 0;
            double OtherFeeNet =0;
            double Total = 0;
            double Balance = 0;
            double Outstanding = 0;
            this.lbPriceADF.Text = "-";
            this.lbPriceAPPF.Text = "-";
            this.lbPriceATF.Text = "-";
            this.lbPriceCOE.Text = "-";
            this.lbPriceEXAMF.Text = "-";
            this.lbPriceOTHF.Text = "-";

            this.lbNPriceADF.Text = "-";
            this.lbNPriceAPPF.Text = "-";
            this.lbNPriceATF.Text = "-";
            this.lbNPriceCOE.Text = "-";
            this.lbNPriceEXAMF.Text = "-";
            this.lbNPriceOTHF.Text = "-";

            this.lbDisADF.Text = "-";
            this.lbDisAPPF.Text = "-";
            this.lbDisATF.Text = "-";
            this.lbDisCOE.Text = "-";
            this.lbDisEXAMF.Text = "-";
            this.lbDisOTHF.Text = "-";
            this.lbTitle.Text = title;
            foreach (ISHCMC_ListInvoiceDetail item in ListInvoiceDetail)
            {
                this.lbInvoiceDebtorName.Text = item.BillingName.ToString();

                this.lbAddress1.Text = item.BillingAddr1;
                this.lbAddress2.Text = item.BillingAddr2;
                this.lbAddress3.Text = item.BillingAddr3;
                this.lbInvoiceNo.Text = item.yourref.ToString();
                if (item.Invoicedate.HasValue)
                {
                    this.lbInvoiceDate.Text = item.Invoicedate.Value.ToString("dd MMM yyyy",System.Globalization.CultureInfo.GetCultureInfo("en"));
                }
                if (item.DueDate.HasValue)
                {
                    this.lbDueDate.Text = item.DueDate.Value.ToString("dd MMM yyyy", System.Globalization.CultureInfo.GetCultureInfo("en"));
                }
                this.lbStudentID.Text = item.StudentID.ToString();
                this.lbStudentName.Text = item.StudentName.ToString();
                this.lbGrade.Text = item.CurrentGrade.ToString();
                lbCOE.Text = "";
                if (itemStudent.COENumber != null)
                {
                    if (itemStudent.COENumber != 0)
                    {
                        this.lbCOE.Text = "COE" + itemStudent.COENumber.ToString("#");
                    }
                }
       
                if (item.EnrolmentDate.HasValue)
                {
                    this.lbEnDate.Text = item.EnrolmentDate.Value.ToString("MMM, yy", System.Globalization.CultureInfo.GetCultureInfo("en"));
                }
             
                if (item.itemcode.Trim() == "APPF")
                {
                    this.lbPriceAPPF.Text = item.Price.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    this.lbNPriceAPPF.Text = item.NetPrice.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    this.lbDisAPPF.Text = item.Discount.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    Total += item.NetPrice;
                }
         
                else if (item.itemcode.Trim() == "TF")
                {
                    this.lbPriceATF.Text = item.Price.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    this.lbNPriceATF.Text = item.NetPrice.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    this.lbDisATF.Text = item.Discount.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    Total += item.NetPrice;
                }
                
                else  if (item.itemcode.Trim() == "ADF")
                {
                    this.lbPriceADF.Text = item.Price.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    this.lbNPriceADF.Text = item.NetPrice.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    this.lbDisADF.Text = item.Discount.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    Total += item.NetPrice;
                }
                else if (item.itemcode.Trim() == "COE")
                {
                    this.lbPriceCOE.Text = item.Price.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    this.lbNPriceCOE.Text = item.NetPrice.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    this.lbDisCOE.Text = item.Discount.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    Total += item.NetPrice;
                }
                else if (item.itemcode.Trim() == "EXAMF")
                {
                    this.lbPriceEXAMF.Text = item.Price.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    this.lbNPriceEXAMF.Text = item.NetPrice.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    this.lbDisEXAMF.Text = item.Discount.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                    Total += item.NetPrice;
                }
                else
                {
                    if (item.itemcode.Trim() != "REENF")
                    {
                        OtherFee += item.Price;
                        OtherFeeNet += item.NetPrice;

                        this.lbPriceOTHF.Text = OtherFee.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                        this.lbNPriceOTHF.Text = OtherFeeNet.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                        this.lbDisOTHF.Text = item.Discount.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
                        Total += item.NetPrice;
                    }
                }
                Outstanding = item.Outstanding;


                this.xrTableCell15.Text = item.description + " Tuition Fee";
            }
            double Paid = 0;
            if (itemStudentPayment != null)
            {
                if (itemStudentPayment.TuitionAmountPaid.HasValue)
                {
                    Paid += Convert.ToDouble(itemStudentPayment.TuitionAmountPaid.Value);
                }
                if (itemStudentPayment.ReenrollAmountPaid.HasValue)
                {
                    Paid += Convert.ToDouble(itemStudentPayment.ReenrollAmountPaid.Value);
                }
                if (itemStudentPayment.ApplicationFeePaid.HasValue)
                {
                    Paid += Convert.ToDouble(itemStudentPayment.ApplicationFeePaid.Value);
                }
            }
            Balance = Total - Paid;
            this.lbTotal.Text = Total.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
            //if (Outstanding > 0)
            //{
            //    this.lbOutstanding.Text = Outstanding.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
            //}
            //if (Outstanding < 0)
            //{
            //    this.lbOutstanding.Text = "(" + (Outstanding * (-1)).ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en")) + ")";
            //}
            //if (Outstanding == 0)
            //{
            //    this.lbOutstanding.Text = "-";
            //}
            if (Paid == 0)
            {
                this.lbOutstanding.Text = "-";
            }
            else
            {
                this.lbOutstanding.Text = Paid.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
            }
            this.lbBalance.Text = Balance.ToString("#,#", System.Globalization.CultureInfo.GetCultureInfo("en"));
        }

        private void lbGrade_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {

        }

    }
}
